<?php

class ElasticSearchController extends BaseController
{

	/*
	|--------------------------------------------------------------------------
	| 首页控制器
	|--------------------------------------------------------------------------
	|
	|
	*/

	public function output()
	{



		//$params = array();
		//$params['index']  = 'udo_index';
		//$params['type']   = 'udo_type';
		//for($i = 0; $i < 100; $i++) {
		//	$params['body'][] = array(
		//		'index' => array(
		//			'_id' => $i
		//		)
		//	);
        //
		//	$params['body'][] = array(
		//		'my_field' => 'my_value',
		//		'second_field' => 'some more values'
		//	);
		//}
		$result = ES_IndexService::instance()->bulkESData();
		dd($result);
		$indexParams = array();
		$indexParams['index']  = 'udo_index';
		$indexParams['type']   = 'udo_type';
		//$indexParams['id']     = 1;
		$fields = array(
			'first_name'	=> 	'abc0',
			'last_name'		=>  'abc1',
			'age'			=>  1
		);
		$indexParams['body']     = $fields;
		//ES_ESService::printfJson($indexParams);
		$result = ES_IndexService::instance()->insertESData($indexParams);
		dd($result);
	}

	public function createIndex()
	{
		$indexParams = array();
		$indexParams['index']  = 'udo_index';
		#shards & replicas
		$indexParams['body']['settings']['number_of_shards']   = 3;
		$indexParams['body']['settings']['number_of_replicas'] = 2;
		#Mapping
		$mapping = array(
			'_source' => array(
				'enabled' => true
			),
			'properties' => array(
				'first_name' => array(
					'type' => 'string',
					'analyzer' => 'standard'
				),
				'last_name' => array(
					'type' => 'string',
					'analyzer' => 'standard'
				),
				'age' => array(
					'type' => 'integer'
				)
			)
		);
		$indexParams['body']['mappings']['udo_type'] = $mapping;
		$result = ES_IndexService::instance()->createESIndex($indexParams);
		dd($result);
	}
}
